<template>
	<view style="font-size: 30upx;padding: 20upx;">
		<view class="title" v-for="(item,index) in showAftersales" :key="index">
			<view style="color: #D7000F;padding: 20upx;text-align: right;">
				<span v-if="item.status === 1">正在审核</span>
				<span v-if="item.status === 2">已通过审核</span>
				<span v-if="item.status === 3">未通过审核</span>
				<span v-if="item.status === 0">已撤回申请</span>
			</view>
	<!-- 	<view>
				<text>订单号：</text>
				<span>{{item.aftersales_id}}</span>
			</view> -->
			<view class="header">
				<image style="width: 180upx;height: 180upx;" :src="item.url"></image>
				<view class="text">
					<text>{{item.name}}</text>
					<view style="display: flex;justify-content: space-between;">
						<text>￥{{item.payed}}</text>
						<text>x{{item.nums}}</text>
					</view>
				</view>
			</view>
			<view class="operation">
				<view class="whole">
					<button class="btn" @click="todetail(item.aftersales_id)">进度查询</button>
					<button v-if="item.status === 1" class="btn" style="background: #D7000F;margin-left: 20upx;" type="primary" @click="deldrawApplication(item.aftersales_id,item.id)">撤回申请</button>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	var _self, page = 1,
		timer = null;
	import {
		get,
		post,
		showToast
	} from '../../js/common';
	export default {
		data() {
			return {
				userId: uni.getStorageSync('userId'),
				showAftersales: [],
				aftersalesId:'',
				loadingText: '加载中...',
				id:'',
				aftersales_id:'',
			}
		},
		onShow() {
			_self = this;
			this.getAftersales()
		},
		onPullDownRefresh() {
			this.getAftersales()
		},
		onReachBottom: function() {
			if (timer != null) {
				clearTimeout(timer);
			}
			timer = setTimeout(function() {
				_self.getmorenews();
			}, 1000);
		},
		methods: {
			getAftersales() {
				page = 1
				uni.showNavigationBarLoading();
				const params = {
					id: this.userId
				}
				post('/mobileapi/mobile/member/usercenter/userShowAftersales', params).then(res => {
					this.showAftersales = res.showAftersales
					page++;
					uni.hideNavigationBarLoading();
					uni.stopPullDownRefresh();
					_self.loadingText = '加载更多';
				})
			},
			getmorenews(status, payStatus, shipStatus, confirm, isComment) {
				if (_self.loadingText != '' && _self.loadingText != '加载更多') {
					return false;
				}
				_self.loadingText = '加载中...';
				uni.showNavigationBarLoading();
				const params = {
					id: this.userId
				}
				post('/mobileapi/mobile/member/usercenter/userShowAftersales', params).then(res => {
					_self.loadingText = '';
					if (res.page == null) {
						uni.hideNavigationBarLoading();
						_self.loadingText = '已加载全部';
						uni.showToast({
							title: '已加载全部'
						})
						return false;
					}
					page++;
					for (let i = 0; i < res.showAftersales.length; i++) {
						_self.showAftersales.push(res.showAftersales[i])
					}
					_self.loadingText = '加载更多';
					uni.hideNavigationBarLoading();
				})
			},
			deldrawApplication(id,orderItemId) {
				try {
					const params = {
						id: id,
						aftersalesItemsId: orderItemId
					}
					post('/mobileapi/mobile/aftersale/drawApplication', params).then(res => {
						if(res.code == 0){
							uni.showToast({
								title:'撤回成功',
								icon:'none'
							})
							this.getAftersales()
						}
					})
				} catch (e) {}
			},
			todetail(aftersalesId) {
				uni.navigateTo({
					url: '/pages/aftersale/after-detail/after-detail?aftersalesId=' + aftersalesId
				})
			}
		}
	}
</script>
<style>
	.title {
		width: 100%;
		background: #ffffff;
		margin-bottom: 20upx;
	}

	.header {
		border-bottom: 2upx solid #E6E6E6;
		display: flex;
		padding: 20upx;
	}

	.text {
		margin-left: 20upx;
		font-size: 26upx;
		color: #666666;
		flex: 1;
	}

	.btn {
		width: 160upx;
		font-size: 26upx;
	}

	.operation {
		display: flex;
		justify-content: space-between;
	}

	.whole {
		padding: 20upx;
		display: flex;
		justify-content: space-between;
	}
</style>
